<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\AgentList
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property string|null $realname 真实姓名
 * @property string|null $id_card 身份证号
 * @property string|null $type 代理人类型 personal：个人 enterprise：企业
 * @property string|null $company_name 单位名称
 * @property string|null $unified_social_credit_code 统一社会信用代码
 * @property string|null $contacts_people 联系人
 * @property string|null $phone 手机号
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\AgentList onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereCompanyName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereContactsPeople($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereIdCard($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereRealname($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereUnifiedSocialCreditCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereUserId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\AgentList withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\AgentList withoutTrashed()
 * @mixin \Eloquent
 * @property float $balance 佣金余额
 * @method static \Illuminate\Database\Eloquent\Builder|\App\AgentList whereBalance($value)
 */
class AgentList extends Model
{
    use SoftDeletes;

    public static function inspectUserWhetherAgent($userId = 0){
        if(empty($userId))
            return 0;

        $result = 0;
        $agent = AgentList::whereUserId($userId)->first();
        if($agent)
            $result = 1;

        $sonAgent = AgentTeam::whereSonAgentUserId($userId)->first();
        if($sonAgent)
            $result = 2;

        return $result;
    }
}
